/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.spielo.crystaldesigner.gui;

import com.spielo.crystaldesigner.dao.PropertyReader;
import com.spielo.crystaldesigner.property.PropertyHolder;
import com.spielo.crystaldesigner.property.PropertyHolder;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Label;
import java.util.HashMap;

/**
 *
 * @author Bernhard
 */
public class PropertyDialog extends javax.swing.JDialog {
    
    private PropertyHolder projectProperties = PropertyHolder.getInstance();
    private HashMap<String, String> packageProperties;

    /**
     * Creates new form PropertyDialog
     */
    public PropertyDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        init();
        this.setSize(this.getWidth()+300, this.getHeight());
        this.setLocationRelativeTo(parent);
    }
    
    private void init()
    {
        //delete later
        PropertyReader pr = new PropertyReader();
        pr.readProperties();
        //
        packageProperties = (HashMap<String, String>) projectProperties.getProperty("packageProperties");
        mainPanel.setLayout(new GridLayout(packageProperties.keySet().size(), 2));
        for(String key : packageProperties.keySet())
        {
            
            String value = packageProperties.get(key);
            key += ": ";
            Label keyLabel = new Label(key);
            Font f = new Font("Tahoma", Font.BOLD, 11);
            keyLabel.setFont(f);
            Label valueLabel = new Label(value);
            mainPanel.add(keyLabel);
            mainPanel.add(valueLabel);
            mainPanel.updateUI();
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        mainPanel = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Package Properties");

        mainPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Properties"));

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 388, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 277, Short.MAX_VALUE)
        );

        jScrollPane1.setViewportView(mainPanel);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jButton1.setText("Close");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onClose(evt);
            }
        });
        getContentPane().add(jButton1, java.awt.BorderLayout.PAGE_END);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void onClose(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onClose
                System.out.println("asdf");
        setVisible(false);
    }//GEN-LAST:event_onClose

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PropertyDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PropertyDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PropertyDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PropertyDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the dialog
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                PropertyDialog dialog = new PropertyDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel mainPanel;
    // End of variables declaration//GEN-END:variables
}
